import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class TestMain {
    private static Map<String,String> goodMap = new HashMap<>();//商品
    private static Map<String,String> limitMap = new HashMap<>();//折扣
    private static Map<String,String> fullMap = new HashMap<>();//满减
    static {
        goodMap.put("苹果","8");
        goodMap.put("草莓","13");
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        //是否需要增加商品
        System.out.print("今天开业了,是否需要增加商品，如需请输入商品名称，无则请回车?:");
        String addGoods = scanner.nextLine();
        while(addGoods != null && !"".equals(addGoods.trim())){
            System.out.print("商品的名称:"+addGoods);//需要将商品加人仓库
            System.out.print("请输入商品的价格:");
            String addAmt = scanner.nextLine();
            goodMap.put(addGoods,addAmt);
            System.out.print("继续添加商品的名称:");
            addGoods = scanner.nextLine();
        }
        System.out.println("是否需要移除商品?:");
        String deleGoods =scanner.nextLine();
        while(deleGoods != null && !"".equals(deleGoods.trim())) {
            System.out.println("移除商品的名称:" + addGoods);
            goodMap.remove(deleGoods);
            addGoods = scanner.nextLine();
        }
        System.out.println("是否需要增加优惠券，如需请输入折扣商品名称?:");
        String addCoupon = scanner.nextLine();
        while(addCoupon != null && !"".equals(addCoupon.trim())) {
            System.out.println("水果的名称:" + addCoupon);//需要商品加人仓库
            System.out.print("请输入折扣:");
            String addAmt = scanner.nextLine();
            limitMap.put(addCoupon, addAmt);
            System.out.println("继续添加折扣商品的名称:");
            System.out.println("继续添加折扣商品的名称:");
            addCoupon = scanner.nextLine();
        }
        System.out.print("是否设置满减活动，需要请输入满减的活动金额：");
        String fullAmt = scanner.nextLine();
        if (null != fullAmt && !"".equals(fullAmt.trim())) {
            System.out.print("是否设置满减活动，需要请输入满减的优惠金额：");
            String amt = scanner.nextLine();
            fullMap.put(fullAmt,amt);
        }
        System.out.println("开业了，今天的商品和价格:"+goodMap.toString());
        System.out.println("客户购买的水果:");
        String name = scanner.nextLine();
        BigDecimal countAmt = new BigDecimal(0);
        while (name != null && !"".equals(name.trim())){
            System.out.print("客户购买的水果数量/斤:");
            String count = scanner.nextLine();
            String amt = goodMap.get(name);
            if (null == amt){System.out.println("当前商品不存在");continue;}
            System.out.println(name+"客户购买的水果和数量:"+count);
            BigDecimal multiply = new BigDecimal(count).multiply(new BigDecimal(amt));
            if (null != limitMap.get(name))multiply = multiply.multiply(new BigDecimal(limitMap.get(name)).divide(BigDecimal.valueOf(10)));
            countAmt = countAmt.add(multiply);
            System.out.println("客户当前商品的总金额:"+countAmt);
            System.out.print("客户继续购买的水果:");
            name =scanner.nextLine();
        }
        if (fullMap.size() > 0){
            for (String value : fullMap.values()) {
                System.out.println("当前的满减金额为："+value);
                if (countAmt.compareTo(new BigDecimal(value)) >= 0)countAmt = countAmt.subtract(new BigDecimal(value));
            }
        }
        System.out.println("客户购买商品的总金额:"+countAmt);
    }
}
